package com.lime49.lockcrypt;
import com.lime49.lockcrypt.ui.AbstractDialog;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.net.URL;

/**
 * The 'About LockCrypt' dialog
 */
public class FrmAbout extends AbstractDialog {
    public FrmAbout(JFrame owner, ResourceBundle lang) {
        super(owner, lang.getString("ABOUTLOCKCRYPT"), true);
        KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
        Action escapeAction = new AbstractAction() {
            // close the frame when the user presses escape
            public void actionPerformed(ActionEvent e) {
                thisDialog.dispose();
            }
        }; 
        thisDialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE");
        thisDialog.getRootPane().getActionMap().put("ESCAPE", escapeAction);
        JPanel abtPanel = new JPanel();
            abtPanel.setLayout(new BoxLayout(abtPanel,BoxLayout.PAGE_AXIS));
            abtPanel.setBorder(Constants.EMPTYBORDER);
            thisDialog.setContentPane(abtPanel);
        JLabel abtTitle = new JLabel("LockCrypt ");
            abtTitle.setFont(abtTitle.getFont().deriveFont(Font.BOLD, 25F));
            abtTitle.setAlignmentX(Component.CENTER_ALIGNMENT);
            abtPanel.add(abtTitle);
        final JLabel abtVersion = new JLabel(lang.getString("VERSION")+" "+Constants.LC_VER);
            abtVersion.setAlignmentX(Component.CENTER_ALIGNMENT);
            abtVersion.setFont(abtVersion.getFont().deriveFont(Font.PLAIN, 12F));
            try {    
                URL iconURL = this.getClass().getResource("images/icon_96.png");
                ImageIcon imgIcon = new ImageIcon(Toolkit.getDefaultToolkit().getImage(iconURL));
                abtVersion.setIcon(imgIcon);
                abtVersion.addMouseListener(new MouseListener() {
                    public void mouseClicked(MouseEvent e) {
                        URL portrait = this.getClass().getResource("images/hjennerway.png");
                        abtVersion.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().getImage(portrait)));
                        pack();
                    }
                    public void mouseEntered(MouseEvent e) {}
                    public void mouseExited(MouseEvent e) {}
                    public void mousePressed(MouseEvent e) {}
                    public void mouseReleased(MouseEvent e) {}
                });
            } catch(Exception ignore) {}
            abtVersion.setHorizontalTextPosition(SwingConstants.CENTER);
            abtVersion.setVerticalTextPosition(SwingConstants.TOP);
            abtPanel.add(abtVersion);
        JLabel abtLockCryptLinkInfo = new JLabel("<html><center>http://www.lockcrypt.com/</center></html>", JLabel.CENTER);
            abtLockCryptLinkInfo.setAlignmentX(Component.CENTER_ALIGNMENT);
            abtLockCryptLinkInfo.setForeground(Color.BLUE);
            abtLockCryptLinkInfo.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            abtLockCryptLinkInfo.addMouseListener(new MouseListener() {
                public void mousePressed(MouseEvent e) {}
                public void mouseReleased(MouseEvent e) {}
                public void mouseEntered(MouseEvent e) {}
                public void mouseExited(MouseEvent e) {}
                public void mouseClicked(MouseEvent e) {
                   Utils.openURL("http://www.lockcrypt.com/");
                }
            });
            abtPanel.add(abtLockCryptLinkInfo);
        JLabel abtInfo = new JLabel("<html><center>Copyright ©2008 - 2009<br>Harry Jennerway</center></html>", JLabel.CENTER);
            abtInfo.setAlignmentX(Component.CENTER_ALIGNMENT);
            abtPanel.add(abtInfo);
            abtPanel.add(Box.createVerticalStrut(10));
        ImageIcon donateIcon = null;
        
        JLabel abtDonate = new JLabel("Donate");
            try {    
                URL donateURL = this.getClass().getResource("images/donate.gif");
                donateIcon = new ImageIcon(Toolkit.getDefaultToolkit().getImage(donateURL));
                abtDonate.setIcon(donateIcon);
                abtDonate.setText("");
            } catch(Exception ignore) {}
            abtDonate.setAlignmentX(Component.CENTER_ALIGNMENT);
            abtDonate.setHorizontalTextPosition(SwingConstants.CENTER);
            abtDonate.setVerticalTextPosition(SwingConstants.TOP);
            abtDonate.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            abtDonate.addMouseListener(new MouseListener() {
                public void mousePressed(MouseEvent e) {}
                public void mouseReleased(MouseEvent e) {}
                public void mouseEntered(MouseEvent e) {}
                public void mouseExited(MouseEvent e) {}
                public void mouseClicked(MouseEvent e) {
                   Utils.openURL("http://www.lockcrypt.com/donate/");
                }
            });
            abtPanel.add(abtDonate); 
            abtPanel.add(Box.createVerticalStrut(10));
            
            
        JLabel abtLime49 = new JLabel("<html><center>Lime49 Software</center></html>", JLabel.CENTER);
            abtLime49.setAlignmentX(Component.CENTER_ALIGNMENT);
            abtPanel.add(abtLime49);
        JLabel abtLime49Link = new JLabel("<html><center>http://www.lime49.com/</center></html>", JLabel.CENTER);
            abtLime49Link.setAlignmentX(Component.CENTER_ALIGNMENT);
            abtLime49Link.setForeground(Color.blue);
            abtLime49Link.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            abtLime49Link.addMouseListener(new MouseListener() {
                public void mousePressed(MouseEvent e) {}
                public void mouseReleased(MouseEvent e) {}
                public void mouseEntered(MouseEvent e) {}
                public void mouseExited(MouseEvent e) {}
                public void mouseClicked(MouseEvent e) {
                   Utils.openURL("http://www.lime49.com/");
                }
            });
            abtPanel.add(abtLime49Link);
            abtPanel.add(Box.createVerticalStrut(10));
            
        JButton btnOk = new JButton(lang.getString("CLOSE"));
            btnOk.setMinimumSize(Constants.MINSIZE);
            btnOk.setPreferredSize(Constants.PREFSIZE);
            btnOk.setMaximumSize(Constants.MAXSIZE);
            btnOk.setAlignmentX(Component.CENTER_ALIGNMENT);
            btnOk.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) { thisDialog.dispose(); }; 
            });
            abtPanel.add(btnOk);
            
            thisDialog.getRootPane().setDefaultButton(btnOk);
            thisDialog.setMinimumSize(new Dimension(200,100));
            thisDialog.pack();
            thisDialog.setLocationRelativeTo(owner);
    }
}
